/*!
 * \file Stage.cpp
 * \brief Implements a Stage class as stage in the execution plan after parsing
 *        the arguments
 *
 * This file contains the implementation for the CLAP :: Stage Class.
 * This is a class to generate a stage to execute given inputs and a set of
 * options and subcommands available.
 */

#include "Stage.h"
#include "Option.h"

using namespace libCLAP;
using namespace libCLAP :: CLAP;

Stage :: Stage ( const Common :: String & name ) :
   _Name ( name )
{
}

Stage :: Stage ( const Stage & copy ) :
   _Name ( copy._Name ),
   _Options ( copy._Options ),
   _Arguments ( copy._Arguments )
{
}

Stage :: ~Stage ( void ) throw ()
{
   map < Common :: String, Option* > :: iterator i;
   for ( i = _Options.begin (); i != _Options.end (); i++ )
   {
      delete ((*i).second);
   }
}

void Stage :: AddOption ( Option & addition )
{
   _Options [ addition.Name () ] = &addition;
}

void Stage :: AddArgument ( Common :: String & addition )
{
   _Arguments.push ( addition );
}

const Common :: String Stage :: Shift ( void )
{
   Common :: String argument = _Arguments.front ();
   _Arguments.pop ();
   return argument;
}

Stage & Stage :: operator = ( const Stage & assign )
{
   _Options = assign._Options;
   _Arguments = assign._Arguments;
   _Name = assign._Name;
   return ( *this );
}

bool Stage :: operator == ( const Stage & compare ) const
{
   if (( _Options == compare._Options ) &&
       ( _Arguments == compare._Arguments ) &&
       ( _Name == compare._Name ))
   {
      return true;
   }
   else
   {
      return false;
   }
}

bool Stage :: operator != ( const Stage & compare ) const
{
   if (( _Options != compare._Options ) &&
       ( _Arguments != compare._Arguments ) &&
       ( _Name != compare._Name ))
   {
      return true;
   }
   else
   {
      return false;
   }
}

bool Stage :: operator < ( const Stage & compare ) const
{
   if (( _Options < compare._Options ) &&
       ( _Arguments < compare._Arguments ) &&
       ( _Name < compare._Name ))
   {
      return true;
   }
   else
   {
      return false;
   }
}

bool Stage :: operator > ( const Stage & compare ) const
{
   if (( _Options > compare._Options ) &&
       ( _Arguments > compare._Arguments ) &&
       ( _Name > compare._Name ))
   {
      return true;
   }
   else
   {
      return false;
   }
}

const map < Common :: String, Option* > & Stage :: Options ( void ) const
{
   return _Options;
}

map < Common :: String, Option* > & Stage :: Options ( void )
{
   return _Options;
}

const queue < Common :: String > & Stage :: Arguments ( void ) const
{
   return _Arguments;
}

const Common :: String & Stage :: Name ( void ) const
{
   return _Name;
}

const queue < Common :: String > & Stage :: Arguments
      ( const queue < Common :: String > & variable )
{
   _Arguments = variable;
   return _Arguments;
}

const map < Common :: String, Option* > & Stage :: Options
      ( const map < Common :: String, Option* > & variable )
{
   _Options = variable;
   return _Options;
}

const Common :: String & Stage :: Name ( Common :: String & variable )
{
   _Name = variable;
   return _Name;
}
